import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import pkg from './package.json'

export default defineConfig({
  build: {
    rollupOptions: {
      external: ['exceljs', /^node:.*/],
      output: {
        globals: {
          exceljs: 'ExcelJS',
        },
      },
    },
  },
  define: {
    'import.meta.env.APP_NAME': JSON.stringify(pkg.name),
    'import.meta.env.APP_VERSION': JSON.stringify(pkg.version),
    'import.meta.env.APP_COMPANY': JSON.stringify(pkg.company || '重庆凯汇科技有限公司'),
  },
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
